package controllers

import (
	"github.com/gin-gonic/gin"
	"github.com/globalsign/mgo/bson"
)

type AdUserQuery struct {
	BaseRequest
	Uid  string `form:"uid"`
	Name string `form:"name"`
}

func GetAdUserList(c *gin.Context) {
	q := &AdUserQuery{}
	if err := c.ShouldBindQuery(&q); err != nil {
		handleErr(c, 404, err.Error())
		return
	}

	mquery := make(map[string]interface{}, 0)
	if q.Uid != "" {
		mquery["_id"] = bson.ObjectIdHex(q.Uid)
	}

	count, err := GameDB.Count("AdUserLog", mquery)
	if err != nil {
		handleErr(c, 404, err.Error())
		return
	}
	logList := make([]interface{}, 0)
	err = GameDB.FindPageSort("AdUserLog", q.Page-1, q.PageNum, mquery, nil, nil, &logList)
	if err != nil {
		handleErr(c, 404, err.Error())
		return
	}
	handleOk(c, map[string]interface{}{"logList": logList, "count": count})
}
